package de.lmu.ifi.pst.uwejsf.framework;


public class NavigationRule {
	private String sourceView;
	private String targetView;
	private String link;
	private String outcome;
	private String targetBean;
	
	public NavigationRule(String sourceView, String targetView,
			String targetBean, String link, String outcome) {
		this.sourceView = sourceView;
		this.targetView = targetView;
		this.targetBean = UWEHelpers.firstToLower(targetBean);
		this.link = link;
		this.outcome = outcome;
	}
	
	public boolean checkCondition() {
		
		NavigationNodeBean nodeBean = (NavigationNodeBean)ExpressionHelpers.resolveValue("#{" + targetBean +"}");
		GuardHandler guardHandler = nodeBean.getGuards().get(link);
		
		return guardHandler.checkCondition(AbstractUWEContextFactory.getCurrentInstance());
	}
	public String follow() {
		NavigationNodeBean nodeBean = (NavigationNodeBean)ExpressionHelpers.resolveValue("#{" + targetBean +"}");
		ContentSelector contentSelector = nodeBean.getContentSelectors().get(link);
		if (contentSelector != null) nodeBean.setActiveContentSelector(contentSelector);
		return "to_" + targetView;
	}
	public String getSourceView() {
		return sourceView;
	}
	public void setSourceView(String sourceView) {
		this.sourceView = sourceView;
	}
	public String getTargetView() {
		return targetView;
	}
	public void setTargetView(String targetView) {
		this.targetView = targetView;
	}
	public String getLink() {
		return link;
	}
	public void setLink(String link) {
		this.link = link;
	}
	public String getOutcome() {
		return outcome;
	}
	public void setOutcome(String outcome) {
		this.outcome = outcome;
	}
	public String getTargetBean() {
		return targetBean;
	}
	public void setTargetBean(String targetBean) {
		this.targetBean = UWEHelpers.firstToLower(targetBean);
	}
	
}
